/**
 * 
 */
package systole.view.crud.tableModels;

import java.util.List;

import systole.domain.clinicalInformation.Sport;
import systole.domain.clinicalInformation.SportPatient;

/**
 * @author jmj
 * 
 */
public class SportsByPatientTableModel extends SystoleTableModel<SportPatient> {

    private String[] columnNames = {"Deporte", "Horas a la semana",
        "Desde hace [años]"};
    private static final int SPORT_INDEX = 0;
    private static final int HOURS_INDEX = 1;
    private static final int START_DATE = 2;

    /**
     * @param sports
     *
     */
    public SportsByPatientTableModel(List<SportPatient> sports) {
        super(sports);
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.swing.table.TableModel#getColumnClass(int)
     */
    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case SPORT_INDEX:
                return Sport.class;
            case HOURS_INDEX:
                return Integer.class;
            case START_DATE:
                return Integer.class;
        }
        return null;
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.swing.table.TableModel#getColumnCount()
     */
    @Override
    public int getColumnCount() {
        return this.columnNames.length;
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.swing.table.TableModel#getColumnName(int)
     */
    @Override
    public String getColumnName(int columnIndex) {
        return this.columnNames[columnIndex];
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.swing.table.TableModel#getValueAt(int, int)
     */
    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case SPORT_INDEX:
                return this.entities.get(rowIndex).getSport();
            case HOURS_INDEX:
                return this.entities.get(rowIndex).getHoursXWeek();
            case START_DATE:
                return this.entities.get(rowIndex).getAgeAtStartAsInteger();
        }
        return null;
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
     */
    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case SPORT_INDEX:
                this.entities.get(rowIndex).setSport((Sport) aValue);
                break;
            case HOURS_INDEX:
                this.entities.get(rowIndex).setHoursXWeek((Integer) aValue);
                break;
            case START_DATE:
                this.entities.get(rowIndex).setAgeAtStartAsInteger((Integer) aValue);
                break;
        }
    }
}
